package com.sgst.job.enums;

import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @description: 仪器状态枚举
 * @author: ftpolaris
 * @date: 2019/10/28
 */
public enum InstrumentState {

    /**
     * 不享受奖励政策-信息更新
     */
    NOT_REWARD_UPDATE("NOT_REWARD_UPDATE", "不享受奖励政策-信息更新", 11),
    /**
     * 可享受奖励政策-信息更新
     */
    REWARD_UPDATE("REWARD_UPDATE", "可享受奖励政策-信息更新", 12),
    /**
     * 不对外提供服务-信息更新
     */
    NOT_SERVICE_UPDATE("NOT_SERVICE_UPDATE", "不对外提供服务-信息更新", 13),

    /**
     * 不公开-信息更新
     */
    NOT_OPEN_UPDATE("NOT_OPEN_UPDATE", "不公开-信息更新", 14),
    /**
     * 子单位还未提交
     */
    SUBUNIT_UN_SUBMIT("SUBUNIT_UN_SUBMIT", "子单位填写中", 0),

    /**
     * 主管单位退回给子单位的状态
     */
    SUBUNIT_MODIFYING("SUBUNIT_MODIFYING", "子单位修改中", 1),

    /**
     * 选择对外提供服务的仪器被提交之后的状态
     */
    LAW_AUDITING("LAW_AUDITING", "子单位填写完整", 2),

    /**
     * 主管单位还未提交
     */
    LAW_UN_SUBMIT("LAW_UN_SUBMIT", "填写中", 3),

    /**
     * 仪器被管理员退回给主管单位的状态
     */
    LAW_MODIFYING("LAW_MODIFYING", "修改中", 4),

    /**
     * 选择对外提供服务的仪器被提交之后的状态
     */
    ADMIN_AUDITING("ADMIN_AUDITING", "专家审核中", 5),

    /**
     * 选择不对外提供服务且信息不公开的仪器提交之后的状态
     */
    NOT_OPEN("NOT_OPEN", "不公开", 6),


    /**
     * 选择不对外提供服务且信息公开的仪器提交之后的状态
     */
    NOT_SERVICE("NOT_SERVICE", "不对外提供服务", 7),

    /**
     * 选择对外提供服务，经管理员审核可享受奖励政策的仪器被审核之后的状态
     */
    REWARD("REWARD", "可享受奖励政策", 8),

    /**
     * 选择对外提供服务，经管理员审核不可享受奖励政策的仪器被审核之后的状态
     */
    NOT_REWARD("NOT_REWARD", "不享受奖励政策", 9),

    /**
     * 报废的仪器
     */
    SCRAP("SCRAP", "报废", 10);

    String state;

    String description;
    Integer stateCode;

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    public Integer getStateCode() {
        return stateCode;
    }

    public void setStateCode(Integer stateCode) {
        this.stateCode = stateCode;
    }
    InstrumentState(String state, String description) {
        this.state = state;
        this.description = description;
    }
    InstrumentState(String state, String description, Integer stateCode) {
        this.state = state;
        this.description = description;
        this.stateCode = stateCode;
    }
    public static InstrumentState getUpdateStateOf(InstrumentState state){
        switch (state){
            case NOT_OPEN:
                return NOT_OPEN_UPDATE;
            case NOT_SERVICE:
                return NOT_SERVICE_UPDATE;
            case REWARD:
                return REWARD_UPDATE;
            case NOT_REWARD:
                return NOT_REWARD_UPDATE;
        }
        return state;
    }

    public static String getStateByUpdateState(String state) {
        switch (getByState(state)){
            case NOT_OPEN_UPDATE:
                return NOT_OPEN.getState();
            case NOT_SERVICE_UPDATE:
                return NOT_SERVICE.getState();
            case REWARD_UPDATE:
                return REWARD.getState();
            case NOT_REWARD_UPDATE:
                return NOT_REWARD.getState();
        }
        return state;
    }
    public static boolean canModify(String state) {
        return Stream.of(NOT_OPEN, NOT_SERVICE, REWARD, NOT_REWARD)
                .map(InstrumentState::getState).collect(Collectors.toSet()).contains(state);
    }
    public static boolean isUpdating(String state) {
        return Stream.of(NOT_OPEN_UPDATE, NOT_SERVICE_UPDATE,REWARD_UPDATE, NOT_REWARD_UPDATE)
                .map(InstrumentState::getState).collect(Collectors.toSet()).contains(state);
    }
    public static InstrumentState getByState(String state){
        return Stream.of(InstrumentState.values())
                .filter(t-> Objects.equals(state, t.getState())).findFirst().orElse(null);
    }

}
